<%@ page contentType="text/html; charset=UTF-8" language="java"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>内容分类</title>
<link rel="stylesheet" type="text/css"	href="../../static/js/themes/defalut.css">
<link rel="stylesheet" type="text/css"	href="../../static/js/themes/public.css">
<link rel="stylesheet" type="text/css"	href="../../static/js/themes/ddspstyle.css">
<link rel="stylesheet" type="text/css"	href="../../static/js/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"	href="../../static/js/themes/icon.css">
<script type="text/javascript" src="../../static/js/jquery.min.js"></script>
<script type="text/javascript" src="../../static/js/jquery.easyui.min.js"></script>
<script type="text/javascript"	src="../../static/js/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="../../static/js/index.js"></script>
<link rel="stylesheet" type="text/css"	href="../../static/zTree/css/zTree.css">
<link rel="stylesheet" type="text/css"	href="../../static/zTree/css/zTreeStyle/zTreeStyle.css">
<link rel="stylesheet" type="text/css"	href="../../static/js/themes/default/easyui.css">
<script type="text/javascript"	src="../../static/zTree/js/jquery.ztree.core.js"></script>
<script type="text/javascript"	src="../../static/zTree/js/jquery.ztree.excheck.js"></script>
<script type="text/javascript"	src="../../static/zTree/js/jquery.ztree.exedit.js"></script>
<%
		String para = request.getParameter("f_cc_id");
		int f_cc_id = 0;
		if(para != null)
			f_cc_id = Integer.valueOf(para);
	%>
<script type="text/javascript">
	var f_cc_id = <%=f_cc_id%>;
	var str="";
	var setting = {
			view: {
				selectedMulti: false
			},
			edit: {
				enable: true,
				editNameSelectAll: true,
				showRemoveBtn: false,
				showRenameBtn: false
			},
			check: {
				enable: true,
				chkStyle: "checkbox",
				chkboxType: { "Y": "", "N": "" }
			},
			data: {
				simpleData: {
					enable: true
				}
			},
			callback: {
				beforeDrag: beforeDrag
			}
		};
		//禁止拖拽
		function beforeDrag(treeId, treeNodes) {
			return false;
		}
		function selectAll() {
			var zTree = $.fn.zTree.getZTreeObj("ztree");
			zTree.setting.edit.editNameSelectAll =  $("#selectAll").attr("checked");
		}
		$(document).ready(function(){
			$.ajax({
				url:"../../catalog/catalog_industry_list.do",
				success:function(data){
					zNodes = JSON.parse(data);
					var root = {id:"0",name:"分类目录",open:true};
					zNodes.push(root);
					var treeObj = $.fn.zTree.init($("#ztree"), setting, zNodes);
					$("#selectAll").bind("click", selectAll);
					treeInit();
					updateNoParentNode(treeObj);
				}
			});
			 /* $.ajax({
				url:"../../statistics/area_tree.do?f_sa_id=0",
				success:function(data) {
					data = JSON.parse(data);
					console.log(data);
					var str = "";
					for(var i=0;i<data.length;i++) {
						str+='<option value="'+data[i].pId+'">'+data[i].name+'</option>';
					}
					//$("#f_sdsa_areaid").append(str);
				}
			});
  */
		});
		
		function updateNoParentNode(treeObj){
			var nodesArr = treeObj.transformToArray(treeObj.getNodes());
			for(var i=0;i<nodesArr.length;i++){
				var rootNode = null;
				if(nodesArr[i].pId == null && nodesArr[i].id == '0'){
					rootNode = nodesArr[i];
					break;
				}
			}
			for(var i=0;i<nodesArr.length;i++){
				if(nodesArr[i].pId == null && nodesArr[i].id != '0'){
					treeObj.moveNode(treeObj.moveNode(rootNode, nodesArr[i], "inner"));
				}
			}
		}
		
		function treeInit() {
			$.ajax({
				url:"../../content/select_catalogBind.do?f_ccc_contentid="+f_cc_id,
				success:function(data) {
					if(data){
						data = JSON.parse(data);
						str = data;
						var treeObj = $.fn.zTree.getZTreeObj("ztree");
						for(var i=0;i<data.length;i++) {
							var node = treeObj.getNodeByParam("id", data[i].f_ccc_catalogid, null);
							node.checked=true;
							treeObj.updateNode(node);
						}
					}
				}
			});
		}
		function _submitFm() {
			var zTree = $.fn.zTree.getZTreeObj("ztree");
			var nodes = zTree.getCheckedNodes(true);
			var instr="";
			var destr="";
			var categoryName="";
			for(var i=0;i<nodes.length;i++) {
					var repeat = 0;
					categoryName+=nodes[i].name;
					for(var j=0;j<str.length;j++) {
						if(nodes[i].id == str[j].f_ccc_catalogid){
							repeat = 1;
						}
					}
					if(repeat == 0){
						instr+=nodes[i].id;
						if(i<nodes.length-1){
							categoryName+=",";
							instr+=",";
						}
					}
					
			}
			for(var i=0;i<str.length;i++) {
				var repeat = 0;
				for(var j=0;j<nodes.length;j++) {
						if(nodes[j].id == str[i].f_ccc_catalogid){
							repeat = 1;
						}
				}
				if(repeat == 0){
					destr+=str[i].f_ccc_catalogid;
					if(i<str.length-1){
						destr+=",";
					}
				}
			}
			if(instr == "" && destr == ""){
				$.messager.alert('提示', "您未进行任何修改，请重新操作！", 'info', function() {
					$.messager.progress('close');
				});
			}else{
				window.parent.document.getElementById("bind_categoryDelStr").value=destr;
				window.parent.document.getElementById("bind_categoryInStr").value=instr;
				window.parent.document.getElementById("bind_categoryName").value=categoryName;
				
				parent.$('#dlg').dialog('close');
				/* $.ajax({
					type:"POST",
					url:"../../update_catalogBind.do",
					data:"f_ccc_contentid="+f_cc_id+"&cataloginStr="+instr+"&catalogdeStr="+destr,
					success:function(data) {
						data = JSON.parse(data);
						if (data.success) {
							$.messager.progress('close');
							$.messager.alert('提示', '修改成功！', 'info', function() {
								parent.$('#dlg').dialog('close');
								parent.gotoSearch($('#easyui-treegrid'));
							});
						} else {
							$.messager.alert('提示', data.result, 'info', function() {
								$.messager.progress('close');
							});
						}
					}
				}); */
			}
		}
	</script>
<title>内容分类</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
</head>

<body class="overfwidth">
	<div class="barnavtop">您所在的位置：内容管理 &gt; 内容分类</div>
	<div id="workspace">
		<ul id="ztree" class="ztree"></ul>
	</div>
	
	<div class="toolbar" style="text-align: center;">
		<a id="easyui-linkbutton" class="easyui-linkbutton"
			data-options="iconCls:'icon-ok'" href="javascript:void(0);"
			onclick="_submitFm()">保存</a> <a href="javascript:void(0);"
			data-options="iconCls:'icon-cancel'" class="easyui-linkbutton"
			onclick="javascript:parent.$('#dlg').dialog('close')">取消</a>
	</div>
</body>
</html>